package gui;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JComboBox;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.List;

import javax.swing.JLabel;

import client.Client;
import client.Item;
import client.catalog;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.border.Border;

public class RemoveItemCatalog extends JPanel{

	private JComboBox jComboBox = null;  //  @jve:decl-index=0:visual-constraint="203,233"
	private JLabel jLabel = null;
	private catalog cat;
	private JPanel jPanel = null;
	private JLabel DelLabel = null;
	private JButton jButton = null;
	JButton backButton = null;
	Border borderColor = BorderFactory.createLineBorder(Color.BLACK);
	private JButton delButton = null;
	private JPanel jPanel1 = null;
	private List <Item> item;
	
	/**
	 * 
	 */
	public RemoveItemCatalog() {
		super();
		initialize();
	}

	private void initialize() {
		this.setSize(700, 387);
		this.setLayout(null);
		this.add(getJLabel(), null);
		this.setBackground(Color.WHITE);
		this.setBorder(borderColor);
		this.add(getJPanel(), null);
		this.add(getBackButton(), null);
		this.add(getDelButton(), null);
		this.add(getJPanel1(), null);
	}

	public void getItems(){
		cat = new catalog();
		Object b = cat.itemDisply();
		item = (List <Item>) b;
		jComboBox.removeAllItems();
		for (int i=0;i<item.size();i++)
			jComboBox.addItem(item.get(i).getName());	
	}
	
	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			cat = new catalog();
			Object b = cat.itemDisply();
			item = (List <Item>) b;
			jComboBox = new JComboBox();
			jComboBox.setBounds(new Rectangle(35, 25, 260, 40));
			for (int i=0;i<item.size();i++)
				jComboBox.addItem(item.get(i).getName());	
		}
		return jComboBox;
	}

	/**
	 * This method initializes jLabel	
	 * 	
	 * @return javax.swing.JLabel	
	 */
	private JLabel getJLabel() {
		if (jLabel == null) {
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(11, 72, 159, 56));
			jLabel.setText("CHOOSE ITEM TO DELETE:");
		}
		return jLabel;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			DelLabel = new JLabel();
			DelLabel.setBounds(new Rectangle(20, 17, 109, 30));
			DelLabel.setText("ITEM DELETED");
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new Rectangle(224, 158, 193, 139));
			jPanel.setBorder(borderColor);
			jPanel.setBackground(Color.green);
			jPanel.add(DelLabel, null);
			jPanel.add(getJButton(), null);
			jPanel.setVisible(false);
		}
		return jPanel;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(53, 77, 77, 37));
			jButton.setText("OK");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					jPanel.setVisible(false);
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes backButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBackButton() {
		if (backButton == null) {
			backButton = new JButton();
			backButton.setBounds(new Rectangle(555, 320, 109, 52));
			backButton.setText("BACK");
		}
		return backButton;
	}

	/**
	 * This method initializes delButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getDelButton() {
		if (delButton == null) {
			delButton = new JButton();
			delButton.setBounds(new Rectangle(533, 84, 96, 36));
			delButton.setText("DELETE");
			delButton.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							String ty = (String)jComboBox.getSelectedItem();
							System.out.println(ty);
							catalog cat1 = new catalog(ty);
							Object b1 = cat1.DeleteItem();
							Boolean del = (Boolean)b1;
							jComboBox.removeAllItems();
							//jPanel.remove(getJComboBox());
							if (!del){
								Object b = cat.itemDisply();
								item = (List <Item>) b;
								for (int i=0;i<item.size();i++)
									jComboBox.addItem(item.get(i).getName());
								//jPanel.add(getJComboBox(),null);
								updateUI();
								jPanel.setVisible(true);
							}
							updateUI();
						}
					});
		}
		return delButton;
	}

	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setLayout(null);
			jPanel1.setBounds(new Rectangle(189, 55, 330, 90));
			jPanel1.add(getJComboBox(),null);
		}
		return jPanel1;
	}


}  //  @jve:decl-index=0:visual-constraint="19,105"
